//
//  TestWorkspace.m
//  sandbox
//
//  Created by 杨岑 on 3/30/15.
//  Copyright (c) 2015 杨岑. All rights reserved.
//

#import "TestWorkspaceWC.h"

@interface TestWorkspaceWC ()

@end

@implementation TestWorkspaceWC

- (void)windowDidLoad {
    [super windowDidLoad];
    
    NSLog(@"%@", [NSWorkspace sharedWorkspace]);
    [NSWorkspace.sharedWorkspace.notificationCenter addObserver:self selector:@selector(observeWorkspace:) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil];
    
    [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(themeChanged:) name:@"AppleInterfaceThemeChangedNotification" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenConfigurationChanged:) name:NSApplicationDidChangeScreenParametersNotification object:nil];
}

- (void)dealloc
{
    [NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self];
}

- (void)themeChanged:(NSNotification*)notification {
    NSLog(@"%@", [NSThread currentThread]);
}

- (void)observeWorkspace:(NSNotification*)notification {
    //NSLog(@"%@", [NSThread currentThread]);
    //NSLog(@"%@ %@", notification.object, notification.userInfo);
    NSWorkspace* space = notification.object;
    NSLog(@"Desktop image on %@: %@", space, [space desktopImageURLForScreen:[NSScreen mainScreen]]);
}

- (void)screenConfigurationChanged:(NSNotification*)notification
{
    NSLog(@"%@", [NSThread currentThread]);
}

- (void)testSelector:(NSString*)a b:(NSString*)b
{
    NSLog(@"%@, %@", a, b);
}

- (void)testSelector:(NSArray*)a
{
    [self testSelector:a[0] b:a[1]];
}

- (IBAction)doTest:(id)sender {
    [self performSelectorOnMainThread:@selector(testSelector:) withObject:@[@"a", @"b"] waitUntilDone:NO];
}

@end
